package com.cn.wanxi.service;

import com.cn.wanxi.model.NewsModel;

import java.util.ArrayList;
import java.util.List;

public class NewsService {
    /**
     * 得到新闻信息
     *
     * @return
     */
    public List<NewsModel> getForNewsList() {
        List<NewsModel> list = new ArrayList<>();
        NewsModel newsModel = new NewsModel();//只是为了获取实体类的数组
        String[] hrefForNews = newsModel.getHrefForNews();
        String[] titleForNews = newsModel.getTitleForNews();
        String[] createTimeForNews = newsModel.getCreateTimeForNews();
        for (int i = 0; i < hrefForNews.length; i++) {
            NewsModel model = new NewsModel();//这个是为了封装新闻信息到前台页面展示
            model.setHref(hrefForNews[i]);
            model.setTitle(titleForNews[i]);
            model.setCreateTime(createTimeForNews[i]);
            list.add(model);
        }
        return list;
    }

    /**
     * 得到网站首页的新闻动态
     *
     * @return
     */
    public List<NewsModel> getForHomeList() {
        List<NewsModel> list = new ArrayList<>();
        NewsModel newsModel = new NewsModel();
        String titles[] = newsModel.getTitlesForHome();
        String contents[] = newsModel.getContentForHome();
        for (int i = 0; i < titles.length; i++) {
            NewsModel model = new NewsModel();
            model.setTitle(titles[i]);
            model.setContent(contents[i]);
            list.add(model);
        }
        return list;
    }
}
